﻿
package extremefx.ui {
	import extremefx.ICloneable;
	import extremefx.IEquatable;		

	/**
	 * @author Marcelo Volmaro
	 */
	public final class KeyCombo implements IEquatable, ICloneable {
		private var _keyCodes:Vector.<uint>;
		
		/**
		 * Creates and defines a KeyCombo.
		 * @param pKeyCodes: An Array of {@code uint} key codes that define a key combination.
		 * @throws ArgumentException if {@code keyCodes} Array contains a value not of type {@code uint} or if the Array contains less than 2 values. 
		 */
		
		public function KeyCombo(pKeyCodes:Vector.<uint>) {
			_keyCodes = keyCodes.concat();
		}
		
		/**
		 * The key codes that compose this KeyCombo.
		 */
		public function get keyCodes():Vector.<uint> {
			return _keyCodes.concat();
		}
		
		/**
		 * Determines if the KeyCombo specified in the {@code keyCombo} parameter is equal to this KeyCombo.
		 * @param keyCombo: The KeyCombo class to compare to this class.
		 * @return Returns {@code true} if the two KeyCombo classes contain the same key codes in the same order; otherwise {@code false}.
		 */
		public function equals(keyCombo:*):Boolean {
			if (keyCombo == this)
				return true;
				
			if (!(keyCombo is KeyCombo)) return false;
			
			return compares(KeyCombo(keyCombo)._keyCodes);
		}
		
		public function compares(pList:Vector.<uint>):Boolean {
			var i:uint = _keyCodes.length;
			if (i != pList.length)
				return false;
			
			while (i--)
				if (_keyCodes[i] != pList[i])
					return false;
			
			return true;
		}
		
		public function clone():Object {
			return new KeyCombo(_keyCodes.concat());
		}
	}
}
